package com.demo.project_template.controller;

import com.demo.project_template.entity.Gift;
import com.demo.project_template.service.GiftService;
import com.demo.project_template.vo.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-21 11:53:54
 */
@Api(tags = "礼物")
@RestController
@RequestMapping("/gift")
public class GiftController {
    @Resource
    private GiftService giftService;

    @ApiOperation(value = "查询礼物列表")
    @GetMapping(value = "/list")
    public R<List<Gift>> list(){
        return R.success(giftService.list());
    }

    @ApiOperation(value = "添加礼物")
    @PostMapping(value = "/add")
    public R<?> add(@RequestBody Gift gift){
        giftService.save(gift);
        return R.success();
    }

    @ApiOperation(value = "修改礼物")
    @PostMapping(value = "/update")
    public R<?> update(@RequestBody Gift gift){
        giftService.updateById(gift);
        return R.success();
    }

    @ApiOperation(value = "删除礼物")
    @DeleteMapping(value = "/id")
    public R<?> delete(@RequestParam Long id){
        giftService.removeById(id);
        return R.success();
    }
}
